using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace IPConfigLibrary
{
    public class Adaptor
    {
        #region Constants
        private const long LONG_ZERO = 0;
        private const int DUMMY_YEAR = 1900;
        #endregion

        #region Members
        private string _ConnectionSpecificDNSSuffix = String.Empty;
        private string _Description = String.Empty;
        private string _PhysicalAddress = String.Empty;
        private bool _DHCPEnabled;
        private bool _AutoConfigurationEnabled;
        private IPAddress _IPAddress = IPAddress.Parse("0.0.0.0");
        private IPAddress _SubnetMask = IPAddress.Parse("0.0.0.0");
        private IPAddress _DefaultGateway = IPAddress.Parse("0.0.0.0");
        private IPAddress _DHCPServer = IPAddress.Parse("0.0.0.0");
        private IPAddress _DNSServer = IPAddress.Parse("0.0.0.0");
        private DateTime _LeaseObtained = new DateTime(1900, 1, 1);
        private DateTime _LeaseExpires = new DateTime(1900, 1, 1);
        #endregion

        #region Properties
        public string ConnectionSpecificDNSSuffix
        {
            get { return _ConnectionSpecificDNSSuffix; }
            set { _ConnectionSpecificDNSSuffix = value; }
        }

        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        public string PhysicalAddress
        {
            get { return _PhysicalAddress; }
            set { _PhysicalAddress = value; }
        }

        public bool DHCPEnabled
        {
            get { return _DHCPEnabled; }
            set { _DHCPEnabled = value; }
        }

        public bool AutoConfigurationEnabled
        {
            get { return _AutoConfigurationEnabled; }
            set { _AutoConfigurationEnabled = value; }
        }

        public IPAddress IPAddress
        {
            get { return _IPAddress; }
            set { _IPAddress = value; }
        }

        public string IPAddress_String
        {
            get
            {
                return _IPAddress.Equals(LONG_ZERO)
                    ? String.Empty
                    : _IPAddress.ToString();
            }
        }

        public IPAddress SubnetMask
        {
            get { return _SubnetMask; }
            set { _SubnetMask = value; }
        }

        public string SubnetMask_String
        {
            get
            {
                return _SubnetMask.Equals(LONG_ZERO)
                    ? String.Empty
                    : _SubnetMask.ToString();
            }
        }

        public IPAddress DefaultGateway
        {
            get { return _DefaultGateway; }
            set { _DefaultGateway = value; }
        }

        public string DefaultGateway_String
        {
            get
            {
                return _DefaultGateway.Equals(LONG_ZERO)
                    ? String.Empty
                    : _DefaultGateway.ToString();
            }
        }

        public IPAddress DHCPServer
        {
            get { return _DHCPServer; }
            set { _DHCPServer = value; }
        }

        public string DHCPServer_String
        {
            get
            {
                return _DHCPServer.Equals(LONG_ZERO)
                    ? String.Empty
                    : _DHCPServer.ToString();
            }
        }

        public IPAddress DNSServer
        {
            get { return _DNSServer; }
            set { _DNSServer = value; }
        }

        public string DNSServer_String
        {
            get
            {
                return _DNSServer.Equals(LONG_ZERO)
                    ? String.Empty
                    : _DNSServer.ToString();
            }
        }

        public DateTime LeaseObtained
        {
            get { return _LeaseObtained; }
            set { _LeaseObtained = value; }
        }

        public string LeaseObtained_String
        {
            get
            {
                return _LeaseObtained.Year.Equals(DUMMY_YEAR)
                    ? String.Empty
                    : _LeaseObtained.ToString("d MMMM yyyy @ HH:mm:ss");
            }
        }

        public DateTime LeaseExpires
        {
            get { return _LeaseExpires; }
            set { _LeaseExpires = value; }
        }

        public string LeaseExpires_String
        {
            get
            {
                return _LeaseExpires.Year.Equals(DUMMY_YEAR)
                    ? String.Empty
                    : _LeaseExpires.ToString("d MMMM yyyy @ HH:mm:ss");
            }
        }
        #endregion

        #region Methods
        #region Constructors
        public Adaptor() { }

        public Adaptor(
            string theConnectionSpecificDNSSuffix,
            string theDescription,
            string thePhysicalAddress,
            bool theDHCPEnabled,
            bool theAutoConfigurationEnabled,
            string theIPAddress,
            string theSubnetMask,
            string theDefaultGateway,
            string theDHCPServer,
            string theDNSServer,
            DateTime theLeaseObtained,
            DateTime theLeaseExpires)
        {
            this._ConnectionSpecificDNSSuffix = theConnectionSpecificDNSSuffix;
            this._Description = theDescription;
            this._PhysicalAddress = thePhysicalAddress;
            this._DHCPEnabled = theDHCPEnabled;
            this._AutoConfigurationEnabled = theAutoConfigurationEnabled;
            IPAddress.TryParse(theIPAddress, out this._IPAddress);
            IPAddress.TryParse(theSubnetMask, out this._SubnetMask);
            IPAddress.TryParse(theDefaultGateway, out this._DefaultGateway);
            IPAddress.TryParse(theDHCPServer, out this._DHCPServer);
            IPAddress.TryParse(theDNSServer, out this._DNSServer);
            this._LeaseObtained = theLeaseObtained;
            this._LeaseExpires = theLeaseExpires;
        }
        #endregion
        #endregion
    }
}
